from django.shortcuts import render, HttpResponse, redirect


def setting(request, project_id):
    return render(request, 'setting.html')


def delete(request, project_id):
    """删除项目"""
    if request.method == 'GET':
        return render(request, 'setting_delete.html')
    project_name = request.POST.get("project_name")
    if not project_name or project_name != request.tracer.project.name:
        return render(request, 'setting_delete.html', {"error": '项目名错误'})
    # 设定只有项目创建者才可以删除项目
    if request.tracer.user != request.tracer.project.creator:
        return render(request, 'setting_delete.html', {"error": "只有项目创建者才可以删除项目"})

    # 1. 删除桶
    # 先删除文件（碎片），再删除桶

    # 2. 删除项目

    return redirect("project_list")

